package com.msoe.client.panels;

import java.util.HashMap;

import com.google.gwt.user.client.ui.*;
import com.msoe.client.Session;
import com.msoe.client.panels.eventhandlers.AccountSettingsEventHandler;
import com.msoe.client.customwidgets.NavigationMenu;

public class AccountSettings implements MSOERPanel {

	public static final String DIV_ID = "account_settings";

	private Panel accountPanel;
	private DecoratorPanel decoration;
	private Session session;
	
	private TextBox T_pass = new PasswordTextBox();
	private TextBox T_newpass = new PasswordTextBox();
	private TextBox T_confirm = new PasswordTextBox();
	
	public AccountSettings(Session session){
		this.session = session;
			
		accountPanel = new VerticalPanel();
		decoration = new DecoratorPanel();
		decoration.add(accountPanel);
		
		NavigationMenu navMenu = new NavigationMenu(this);
		Label L_Change_Password = new Label("Change Password");
		Label L_Password = new Label("Current Password:");
		Label L_New_Password = new Label("New Password:");
		Label L_Confirm_Password = new Label("Confirm New Password:");
		Button B_Save = new Button("Save Changes");
		
		AccountSettingsEventHandler handler = new AccountSettingsEventHandler(this);
		B_Save.addClickListener(handler);
		
		accountPanel.add(navMenu);
		accountPanel.add(L_Change_Password);
		accountPanel.add(L_Password);
		accountPanel.add(T_pass);
		accountPanel.add(L_New_Password);
		accountPanel.add(T_newpass);
		accountPanel.add(L_Confirm_Password);
		accountPanel.add(T_confirm);
		accountPanel.add(B_Save);
	}
	
	public Session getSession() {
		return session;
	}
	
	public void hide() {
		accountPanel.removeFromParent();
	}

	public void show() {
		if(session.validate()){
			clear();
			RootPanel.get().clear();
			RootPanel.get(DIV_ID).add(accountPanel);
		}
		else{
			PanelMap.getPanel("Login").show();
		}
	}
	
	public HashMap<String, String> getFields(){
		HashMap<String, String> fields = new HashMap<String, String>();
		
		fields.put("password", T_pass.getText());
		fields.put("new", T_newpass.getText());
		fields.put("confirm", T_confirm.getText());
		
		return fields;
	}
	
	private void clear(){
		T_confirm.setText("");
		T_newpass.setText("");
		T_pass.setText("");
	}

}
